﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Agr.CQRS.Domain.Commands;

namespace Agr.Questionnaire.Core.Domain.Qnnaire.Commands
{
    [Serializable]
    public class AddTextQuestion : Command
    {
        public string SectionName { get; set; }
        public string QuestionText { get; set; }
    }

    public class AddTextQuestionHandler : CommandHandler<AddTextQuestion>
    {
        protected override void ExecuteInternal(AddTextQuestion command)
        {
            var q = GetById<Questionnaire>(command.AffectedAggregateRootId, command.AffectedVersion);
            var s = q.GetSection(command.SectionName);
            if (s == null)
                throw new InvalidCommandException("Section {0} not found", command.SectionName);

            s.AddNewTextQuestion(command.QuestionText);
        }
    }


}
